package com.his.controller;

import com.his.bean.DzmHisRegisteredfee;
import com.his.bean.DzmHisRegisteredfeeSub;
import com.his.service.DzmHisRegisteredfeeService;
import com.his.service.DzmHisRegisteredfeeSubService;
import com.his.utils.ResponseResult;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/registeredfees")
public class DzmHisRegisteredfeeController {
    @Autowired
    DzmHisRegisteredfeeService dzmHisRegisteredfeeService;
    @Autowired
    DzmHisRegisteredfeeSubService dzmHisRegisteredfeeSubService;
@GetMapping("/selects")
    public ResponseResult selectAll(DzmHisRegisteredfee dzmHisRegisteredfee){
        List<DzmHisRegisteredfee> list = dzmHisRegisteredfeeService.selectAll(dzmHisRegisteredfee);
        return new ResponseResult(200,"成功",list);
    }
@PostMapping("/add")
    public ResponseResult insert(DzmHisRegisteredfee dzmHisRegisteredfee){
    System.out.println(dzmHisRegisteredfee);
        dzmHisRegisteredfeeService.insert(dzmHisRegisteredfee);
        return new ResponseResult(200,"成功");
    }
@GetMapping("/select/{regId}")
public ResponseResult selectById(@PathVariable Integer regId){
    System.out.println(regId+"id");
     DzmHisRegisteredfee dzmHisRegisteredfee= dzmHisRegisteredfeeService.selectById(regId);
    return new ResponseResult(200,"成功",dzmHisRegisteredfee);
}
@PostMapping("/updates")
public ResponseResult update(DzmHisRegisteredfee dzmHisRegisteredfee){
    dzmHisRegisteredfeeService.updatefee(dzmHisRegisteredfee);
    return new ResponseResult(200,"成功");
}

@PostMapping("/deletes/{regId}")
public ResponseResult delete(@PathVariable Integer regId){
    dzmHisRegisteredfeeService.delete(regId);
    return new ResponseResult(200,"成功");
}

@RequestMapping("/addTwo")
    public ResponseResult addTwo(@RequestBody Map<String,Object> map){


    System.out.println(map);
//    dzmHisRegisteredfeeSubService.add();
    dzmHisRegisteredfeeService.addReg(map);
    int newid=dzmHisRegisteredfeeService.getNewId();
    System.out.println(newid +"newid");

    List<Map> courseInfo = (List<Map>) map.get("courseInfo");
    System.out.println(courseInfo+"cou");
    for (Map map1 : courseInfo) {
        map1.put("regId",newid);
        dzmHisRegisteredfeeSubService.addSub(map1);
    }

    return new ResponseResult(200,"挂号以及子费用",map);
}
}
